package jiekoudeshiyongshili;

import java.util.Optional;

class A implements Cloneable{
    public int a;

    public void setA(int a) {
        this.a = a;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
public class One implements Comparable<One> ,Cloneable {
    public String name;
    public int age;
    public A a = new A();

    public One(String name, int age) {
        this.name = name;
        this.age = age;
    }

    class inner_one{
        int aa = 0;
    }

    @Override
    public int compareTo(One o) {
        return this.age - o.age;
        //return this.name.compareTo(o.name);//String也是实现了compareTo接口这里调用的compareTo不是自己写的compareTo
        //是String实现compareTo的接口的方法
    }


    @Override
    protected Object clone() throws CloneNotSupportedException {
        //return super.clone();
        //深拷贝
        One tmp = (One) super.clone();
        tmp.a = (A) this.a.clone();
        return tmp;
    }

    public String toString() {
        return "One{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
